package com.hishop.controller.portal;

import com.github.pagehelper.PageInfo;
import com.hishop.common.ServerResponse;
import com.hishop.service.IProductService;
import com.hishop.vo.ProductDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Restful接口改造:资源定位符，不是所有接口都适合restful化。比方说：新增接口和修改接口
 * Created by hejie on 2017/7/20.
 */
@Controller
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private IProductService iProductService;

    @RequestMapping("/{productId}")
    @ResponseBody
    public ServerResponse<ProductDetailVo> detail(@PathVariable Integer productId) {
        return iProductService.getProductDetail(productId);
    }

    @RequestMapping("list.do")
    @ResponseBody
    public ServerResponse<PageInfo> list(@RequestParam(value = "keyWord", required = false) String keyWord, @RequestParam(value = "categoryId", required = false) Integer categoryId, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum
            , @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, @RequestParam(value = "orderBy", defaultValue = "") String orderBy) {

        return iProductService.getProductListByKeywordCategory(keyWord, categoryId, pageNum, pageSize, orderBy);
    }

}
